<template>
  <div class="main-r">
    <div class="list_b" :style="{ background: `rgb(${colors[0]})` }">
      <!-- <div class="imgbg">
        <img :src="singListDetail.coverImgUrl" alt="">
      </div> -->
      <div class="list-nav">
        <div class="iconfont icon-zuojiantou" @click="goBack"></div>
        <div class="list_text">歌单</div>
        <van-icon name="search" />
      </div>
      <div class="list-bg">
        <div class="list-bg_l">
          <img
            id="background"
            :src="singListDetail.coverImgUrl"
            crossorigin="anonymous"
          />
        </div>
        <div class="list-bg_r">
          <div class="list-bg-name">{{ singListDetail.name }}</div>
          <div class="list-bg-cr">
            <div class="list-bg-photo">
              <img :src="singListDetail.creator.avatarUrl" />
            </div>
            <div class="list-ce-name">
              {{ singListDetail.creator.nickname }}
            </div>
            <div class="iconfont icon-dibudaohanglan-"></div>
          </div>
        </div>
      </div>
    </div>
    <Scroll ref="scroll" class="content" :h="50">
      <div class="list-item">
        <div class="sing-item" v-for="(item, index) in allSong">
          <div class="index">{{ index + 1 }}</div>
          <div class="sing">
            <div class="sing_top">
              <div class="sing-name">{{ item.name }}</div>
              <!-- <div class="or_singer" v-show="item.song.alia[0]!==''">{{ item.song.alia[0] }}</div> -->
            </div>
            <div class="sing_bottom">
              <span class="singer">{{ item.ar[0].name }}</span>
              <span style="margin: 0 5px;">-</span>
              <span class="issue">{{ item.al.name }}</span>
            </div>
          </div>
          <div class="iconfont icon-iconset0481"></div>
        </div>
      </div>
    </Scroll>
  </div>
</template>
<script>
import Vue from "vue";
import { Icon } from "vant";
import { mapGetters, mapState } from "vuex";
import Scroll from "@/components/global/scroll";
import ColorThief from "colorthief";
Vue.use(Icon);
export default {
  data() {
    return {
      colors: [],
      url: "",
    };
  },
  components: {
    Scroll,
  },
  computed: {
    ...mapGetters(["singListDetail", "allSong"]),
  },
  created() {
    this.$bus.$emit("hideMenu", false);
    let arr = this.$store.getters.singListDetail.trackIds;
    for (let i = 0; i < arr.length; i++) {
      this.$store.dispatch("getAllSong", arr[i].id);
    }
  },
  mounted() {
    this.ImgColor()
    this.$store.commit("clearData");
  },
  beforeDestroy() {
    this.$bus.$emit("hideMenu", true);
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    ImgColor() {
      // this.$axios.get(`https://autumnfish.cn/song/detail`,
      //     {params: {ids: 210042}}).then((song) => {
      //     this.url = song.data.songs[0].al.picUrl;
      this.url = this.$store.getters.singListDetail.coverImgUrl;
      // console.log(url);
      let domImg = document.querySelector("#background");
      let colorthief = new ColorThief();
      domImg.addEventListener("load", () => {
        // console.log('加载好了并取色', colorthief.getPalette(domImg, 2));//第二个参数可选(1~10)
        this.colors = colorthief.getPalette(domImg,2);
      });
    },
    // }
  },
};
</script>

<style lang="scss">
.main-r {
  .list_b {
    background-color: #fff;
    width: 100%;
    // background: rgb(6, 90, 6);
    position: fixed;
    top: 0;
    z-index: 2;
    .imgbg {
      position: absolute;
      height: 204px;
      width: 100%;
      filter: blur(50px);
      // transform-origin:left;
      z-index: -1;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .list-nav {
      display: flex;
      font-size: 16px;
      line-height: 44px;
      padding: 0 10px;
      color: #fff;
      .iconfont {
        font-size: 20px;
        width: 10%;
      }
      .list_text {
        width: 80%;
      }
      /deep/.van-icon {
        font-size: 20px;
        line-height: 44px;
      }
    }
    .list-bg {
      position: relative;
      overflow: hidden;
      padding: 30px 15px;
      .list-bg_l {
        width: 100px;
        height: 100px;
        border-radius: 15px;
        // background: fuchsia;
        float: left;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .list-bg_r {
        float: left;
        margin-left: 20px;
        font-size: 18px;
        color: #fff;
        .list-bg-name {
          width: 200px;
          overflow: hidden;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .list-bg-cr {
          display: flex;
          line-height: 28px;
          margin-top: 15px;
          .list-bg-photo {
            width: 25px;
            height: 25px;
            border-radius: 50%;
            // background: lightcoral;
            overflow: hidden;
            img {
              width: 100%;
              height: 100%;
            }
          }
          .list-ce-name {
            margin-left: 10px;
            font-size: 12px;
            color: #999;
          }
        }
      }
    }
  }
  .list-item {
    margin-top: 204px;
    .sing-item {
      padding: 10px 10px;
      display: flex;
      align-items: center;
      .index {
        font-size: 18px;
        color: #666;
      }
      .sing {
        margin: 0 10px;
        width: 80%;
        .sing_top {
          font-size: 16px;
          color: #000;
          display: flex;
          // font-weight: 600;
          .or_singer {
            margin-left: 10px;
            font-size: 14px;
            color: #999;
          }
        }
        .sing_bottom {
          margin-top: 5px;
          display: flex;
          color: #999;
          font-size: 12px;
        }
      }
    }
  }
}
</style>
